1 : <?php
2 :
3 : //require_once "Zend/Gdata/Calendar.php";
4 : //require_once "Zend/Gdata/ClientLogin.php";
5 :
6 : //require_once PATH_TO_ROOT . "calendariface.iimport.inc.php";
7 :
8 : class Import_GCalendar {
9 :
10 : private $service;
11 :
12 : public function __construct( $user, $passwd ) {
13 : // Performance Tweak. Inclusion der Benötigten Dateien nur bei Instantiierung der Klasse.
14 0 : require_once "Zend/Gdata/Calendar.php";
15 0 : require_once "Zend/Gdata/ClientLogin.php";
16 0 : $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
17 0 : $client = Zend_Gdata_ClientLogin::getHttpClient($user, $passwd, $service);
18 0 : $this->service = new Zend_Gdata_Calendar($client);
19 0 : }
20 :
21 : private function query() {
22 0 : $query = $this->service->newEventQuery();
23 0 : $query->setUser('default');
24 0 : $query->setVisibility('private');
25 0 : $query->setProjection('full');
26 0 : $query->setOrderby('starttime');
27 : //$query->setFutureevents('true');
28 0 : }
29 :
30 : private function eventFeed( $query ) {
31 0 : return $this->service->getCalendarEventFeed($query);
32 : }
33 :
34 : private function isWholeDay( $start, $end ) {
35 0 : if ((strtotime($end) - strtotime($start)) == (24*60*60)) {
36 0 : return true;
37 : }
38 :
39 0 : return false;
40 : }
41 :
42 : public function events() {
43 0 : $this->events = array();
44 0 : foreach ($this->eventFeed($this->query()) as $event) {
45 : // Mapping:
46 0 : static $googleEventCount = 1;
47 0 : $entry = array();
48 :
49 0 : if (empty($event->when)) continue;
50 :
51 0 : $entry['eventtime'] = strtotime((string)$event->when[0]->startTime);
52 : // Kennt eStudy nicht!
53 0 : $end = (string)$event->when[0]->endTime;
54 0 : $entry['eventtime'] = date("Y-m-d H:i:s",$entry['eventtime']);
55 0 : $entry['wholetime'] = $this->isWholeDay( $entry['eventtime'], $end );
56 0 : $entry['eventsubject'] = (string)$event->title;
57 0 : $entry['eventtext'] = (string)$event->content;
58 0 : $entry['eventid'] = "Google";
59 0 : $entry['googleEventCount'] = $googleEventCount;
60 0 : $entry['canEditEvent'] = "0";
61 0 : $this->events[] = $this->packAsArray($entry);
62 0 : $googleEventCount++;
63 0 : }
64 0 : return $this->events;
65 : }
66 :
67 : private function packAsArray( $event ) {
68 0 : $result = array();
69 0 : $result[0] = $event;
70 :
71 0 : return $result;
72 : }
73 :
74 : public function getEvent( $id ) {
75 0 : foreach ($this->events as $event) {
76 0 : $theEvent = $event[0];
77 0 : if ($theEvent['googleEventCount'] == $id) {
78 0 : return $theEvent;
79 : }
80 0 : }
81 0 : }
82 : }
|